package Meins;

import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.media.j3d.*;
import javax.vecmath.*;
 
import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
 
/**
 * @author Thomas.Darimont
 * 
 */
public class Java3DExample extends JFrame{
 
    public Java3DExample(){
        super("Java3DExample");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Canvas3D canvas = new Canvas3D(SimpleUniverse
                .getPreferredConfiguration());
        canvas.setSize(320, 240);
        SimpleUniverse simpleUniverse = new SimpleUniverse(canvas);
        simpleUniverse.getViewingPlatform().setNominalViewingTransform();
        
        BranchGroup rootBranchGroup = new BranchGroup();
        TransformGroup rootTransformGroup = new TransformGroup();
        rootBranchGroup.addChild(rootTransformGroup);
        rootTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        ColorCube colorCube = new ColorCube();
        rootTransformGroup.addChild(colorCube);
        
        BoundingSphere boundingSphere = new BoundingSphere(new Point3d(0,0,0),100);
        
        MouseRotate mouseRotate = new MouseRotate();
        mouseRotate.setTransformGroup(rootTransformGroup);
        mouseRotate.setSchedulingBounds(boundingSphere);
        rootBranchGroup.addChild(mouseRotate);
 
        MouseTranslate mouseTranslate = new MouseTranslate();
        mouseTranslate.setTransformGroup(rootTransformGroup);
        mouseTranslate.setSchedulingBounds(boundingSphere);
        rootBranchGroup.addChild(mouseTranslate);
        
    
        
        MouseZoom mouseZoom = new  MouseZoom();
        mouseZoom.setTransformGroup(rootTransformGroup);
        mouseZoom.setSchedulingBounds(boundingSphere);
        rootBranchGroup.addChild(mouseZoom);
        
        KeyNavigatorBehavior keyNavigatorBehavior = new KeyNavigatorBehavior(rootTransformGroup);
        keyNavigatorBehavior.setSchedulingBounds(boundingSphere);
        rootBranchGroup.addChild(keyNavigatorBehavior);
        
        rootBranchGroup.compile();
        
        simpleUniverse.addBranchGraph(rootBranchGroup);
        
        
        add(canvas);
        pack();
        setVisible(true);
    }
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        new Java3DExample();
    }
 
}